const vm = new Vue({
    el:'#root',
    data(){
        return{
            // sum:0,
            bookData:[
                {
                    id:1,name:"<<算法导论>>",date:"2006-9",price:85,number:"1"
                },
                {
                    id:2,name:"<<UNIX编程艺术>>",date:"2006-2",price:49,number:"1"
                },
                {
                    id:3,name:"<<编程珠玑>>",date:"2008-10",price:39,number:"1"
                },
                {
                    id:4,name:"<<代码大全>>",date:"2006-3",price:128,number:"1"
                }
            ]
        }
    },
    methods: {
        remove(e,i){
            this.bookData.splice(i,1);
        },
        subtract(item){
            item.number = item.number <= 0 ? 0 : (item.number-1);
        },
        add(item){
            item.number++;
            console.log(item.number);
        },
        change(){
            console.log("Change");
        }
        
    },
    computed:{
        sum(){
            sum = 0
            for(let i = 0 ; i < this.bookData.length ; i++)
            {
                sum += this.bookData[i].price * this.bookData[i].number;
            };
            return sum.toFixed(2);
        }
    },
    filters:{
        tosum:function(sum){
            return Symbol.toFixed(2);
        }
    }
    
})